package com.ap.autobase.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.ap.autobase.domain.Order;
import com.ap.autobase.services.LocationService;
import com.ap.autobase.services.OrderService;
import com.ap.autobase.services.RaceService;
import com.ap.autobase.services.TransportService;

@Controller
public class OrderController {
	@Autowired
	OrderService orderService;
	
	@Autowired
	TransportService transportService;
	
	@Autowired
	LocationService placeService;
	
	@Autowired
	RaceService raceService;
	
	@RequestMapping(value = "/order/info", method = RequestMethod.GET)
	public ModelAndView info(String order_name){
		ModelAndView mav = new ModelAndView("order/order-info");
		//mav.addObject("request", "order_name");
		return mav;
		
	}
	
	@RequestMapping(value = "/order/search", method = RequestMethod.GET)
	public ModelAndView search(
			@RequestParam(value = "identificator", required = true) String identificator,
			HttpServletRequest request, HttpSession session){
		ModelAndView mav = new ModelAndView("order/order-info");
		Order order = new Order();
		
		String message = identificator;
		try {
			order = orderService.getOrderById(1);
		}
		catch(Exception e){
			message = "error";
		}
		
		if (order!=null){
				
		}
		
		mav.addObject("order", message);
		return mav;
		
	}
	
	@RequestMapping(value = "/order/new", method = RequestMethod.GET)
	public ModelAndView newOrder(String order_name){
		//orderService.addOrder(order_name);
		ModelAndView mav = new ModelAndView("order/order-new");
		//mav.addObject("request", "order_name");
		return mav;
		
	}
	
	@RequestMapping(value = "/order/ordered", method = RequestMethod.GET)
	public ModelAndView orderResult(String order_name){
		//orderService.addOrder(order_name);
		ModelAndView mav = new ModelAndView("ordered");
		//mav.addObject("request", "order_name");
		return mav;
		
	}

}
